package com.mirror.utils.base;

import android.os.AsyncTask;
import android.view.View;

/**
 * 任务的基类
 * <p>
 * Copyright: Copyright (c) 2013-5-3 上午11:01:55
 * <p>
 * Company: 北京幻方朗睿技术有限公司
 * <p>
 * Author: 李晖
 * <p>
 * Version: 1.0
 * <p>
 */
public class BaseTask extends AsyncTask<String, Void, String> {

	/** 触发事件的按钮 */
	private View[] fromView;

	/** 事件处理结束后需要显示的按钮 */
	private View[] toView;

	/** 加载按钮 */
	private View loadingView;

	public BaseTask(Object... object) {
	}

	/**
	 * 显示加载按钮
	 */
	protected void showLoadingView(View[] fromView, View[] toView, View loadingView) {
		setFromView(fromView);
		setToView(toView);
		setLoadingView(loadingView);
		if (fromView != null && fromView.length > 0) {
			for (View view : fromView) {
				view.setVisibility(View.GONE);
			}
		}
		if (loadingView != null) {
			loadingView.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 操作失败还原加载按钮
	 */
	protected void resumeLoadingView() {
		if (fromView != null && fromView.length > 0) {
			for (View view : fromView) {
				view.setVisibility(View.VISIBLE);
			}
		}
		if (loadingView != null) {
			loadingView.setVisibility(View.GONE);
		}
	}

	/**
	 * 隐藏加载按钮
	 */
	protected void hideLoadingView() {
		if (loadingView != null) {
			loadingView.setVisibility(View.GONE);
		}
		if (toView != null && toView.length > 0) {
			for (View view : toView) {
				view.setVisibility(View.VISIBLE);
			}
		}
	}

	@Override
	protected void onProgressUpdate(Void... voids) {
		super.onProgressUpdate(voids);
	}

	@Override
	protected String doInBackground(String... params) {
		return null;
	}

	public View[] getFromView() {
		return fromView;
	}

	public void setFromView(View[] fromView) {
		this.fromView = fromView;
	}

	public View[] getToView() {
		return toView;
	}

	public void setToView(View[] toView) {
		this.toView = toView;
	}

	public View getLoadingView() {
		return loadingView;
	}

	public void setLoadingView(View loadingView) {
		this.loadingView = loadingView;
	}
}
